// *************************************
// EFMP Fleet
// DataSetup.do
// *************************************

/*
// Description
// ----------------------------
This program analyses the Enhanced Fleet Modernization Program (EFMP) in 
California.  It prepares the fleet data, fuel efficiency data and
EFMP rebate data for later analysis.

*/


/*** START CODE ***/


// Preamble
// ----------------------------
capture log close
clear all
version 14.2
set more off
set matsize 800


// Setup
// ----------------------------

use "${DisCommData}/ExperianMaster.dta", clear
keep if OwnerState == "CA"

** Restrict to period of interest
** NB - Only vehicles younger than 8 years are eligible for the EFMP
local StartDate = date("March 1 2010", "MDY")
keep if PurchaseDate > `StartDate'

gen quarter = quarter(PurchaseDate)
drop year
gen year = year(PurchaseDate)
ren VehicleMake make
ren VehicleModel model
ren VehicleYear modelyr

replace make = upper(trim(make))
replace model = upper(trim(model))

gen countE1to4_total = 1
replace VehicleType = "" if VehicleType == "OTHER"
replace VehicleType = "ICE" if VehicleType == "Conventional"
replace VehicleType = "HEV" if VehicleType == "Hybrid"

foreach type in BEV ICE HEV PHEV {
	gen countE1to4_`type' = VehicleType == "`type'" if !mi(VehicleType)
	
}

// make adjustments to strings
replace model = "ACCORD" if make == "HONDA" & regexm(model, "ACCORD") == 1

preserve
	keep if VehicleType == "BEV" | VehicleType == "PHEV"
	
	replace model = subinstr(model, " ", "_", .) 
	replace model = subinstr(model, "-", "_", .) 
	replace make = subinstr(make, "-", "_", .) 
	levelsof make, local(makes) 
	tempfile tempsave
	save `tempsave', replace

	use `tempsave', clear
	gen c_ = 1
	gcollapse (sum) c_, by(modelyr year)
	reshape wide c_, i(modelyr) j(year)
	forvalues i = 2011/2017 {
		cap la var c_`i' "transaction year `i'"
	}
	la var modelyr "model year"

	export excel using  "${EFMPFleetRes}/Data_Check/modelyr_year.xlsx", replace sheet("All makes") firstrow(varlabel)

	foreach make of local makes {
		use `tempsave', clear
		keep if make == "`make'"
		gen c_ = 1
		gcollapse (sum) c_, by(modelyr year)
		reshape wide c_, i(modelyr) j(year)
		forvalues i = 2011/2017 {
			cap la var c_`i' "trans `i'"
		}
		la var modelyr "model year"
		export excel using  "${EFMPFleetRes}/Data_Check/modelyr_year.xlsx", sheetreplace sheet("`make'") firstrow(varlabel)
			
	}
restore


gcollapse (sum) countE1to4_total countE1to4_BEV countE1to4_ICE countE1to4_HEV countE1to4_PHEV, by(make model modelyr year quarter)
foreach type in BEV ICE HEV PHEV {
	replace countE1to4_`type' = . if countE1to4_`type' == 0 
	
}
save "${EFMPFleetData}/counts_E1to4.dta", replace

// New Fleet Data 
// ----------------------------
use "${Experian}/DataOut/UCDavis_Final_File_20190928.dta", clear

drop state 
replace make = upper(trim(make))
replace model = upper(trim(model))
ren censustract tract
tostring tract, format(%12.0f) replace

gen len = length(tract)
keep if len == 10
drop len

destring month, replace
gen quarter = inlist(month, 1, 2, 3) if !mi(month)
replace quarter = 2 if inlist(month, 4, 5, 6) == 1
replace quarter = 3 if inlist(month, 7, 8, 9) == 1
replace quarter = 4 if inlist(month, 10, 11, 12) == 1
ta quarter


preserve 
	keep year month make model modelyr fuel quarter cnt_total
	replace fuel = "ICE" if inlist(fuel, "Diesel", "Gasoline/Flex") == 1
	replace fuel = "" if fuel == "Other"
	replace fuel = "BEV_PHEV" if fuel == "Electric"
	replace fuel = "HEV_PHEV" if fuel == "Hybrid"
	ren cnt_total countE5_
	gcollapse (sum) countE5_, by(year quarter make model modelyr fuel)
	drop if fuel == ""
	reshape wide countE5_, i(year make model modelyr quarter) j(fuel) string
	save "${EFMPFleetData}/counts_E5.dta", replace
restore

preserve
	use "${EFMPFleetData}/counts_E1to4.dta", clear
	keep if regexm(model, "PRIUS") == 1
	drop countE1to4_BEV countE1to4_HEV countE1to4_ICE countE1to4_PHEV
	order make year quarter
	sort make year quarter model modelyr
	export excel using "${EFMPFleetRes}/${ResultsVersion}/Data_Check/Prius_transactions_detail.xlsx", firstrow(variables) replace
restore 
preserve
	use "${EFMPFleetData}/counts_E5.dta", clear
	merge 1:1 year make model modelyr quarter using "${EFMPFleetData}/counts_E1to4.dta" 
	drop if year <=2013 | (year == 2014 & quarter != 4)
	gen PHEV_or_HEV = !mi(countE1to4_HEV) & !mi(countE1to4_PHEV) 
	gen PHEV_or_BEV = !mi(countE1to4_BEV) & !mi(countE1to4_PHEV) 
	keep if PHEV_or_HEV == 1 | PHEV_or_BEV == 1
	assert _merge == 3
	drop _merge
		
	
	egen countE1to4_BEV_PHEV = rowtotal(countE1to4_BEV countE1to4_PHEV)
	replace countE1to4_BEV_PHEV = . if countE1to4_BEV_PHEV == 0
	egen countE1to4_HEV_PHEV = rowtotal(countE1to4_HEV countE1to4_PHEV)
	replace countE1to4_HEV_PHEV = . if countE1to4_HEV_PHEV == 0
	la var countE5_BEV_PHEV "Number of transactions E5"
	la var countE1to4_BEV_PHEV "Number of tansactions E1 to 4"
	la var countE5_HEV_PHEV   "Number of transactions E5"
	la var countE1to4_HEV_PHEV "Number of tansactions E1 to 4"
	sort make model modelyr year quarter 
	drop countE1to4_total

	// create shares of Phevs in a category that is either PHEV or HEV
	gen shPHEV_in_HEV_PHEV = countE1to4_PHEV/countE5_HEV_PHEV if PHEV_or_HEV == 1
	*replace shPHEV_in_HEV_PHEV = 1 if shPHEV_in_HEV_PHEV > 1 & !mi(shPHEV_in_HEV_PHEV)
	// create shares of BEVs in a category that is either BEV or PHEV
	gen shBEV_in_BEV_PHEV = countE1to4_BEV/countE1to4_BEV_PHEV if PHEV_or_BEV == 1

	scatter countE5_BEV_PHEV countE1to4_BEV_PHEV, title("Count of BEVs or PHEVs across datasets")  graphregion(color(white))  
	graph export "${EFMPFleetRes}/Data_Check/counts_E5_vs_E1to4_BEV_PHEV.png", replace
	scatter countE5_HEV_PHEV countE1to4_HEV_PHEV, title("Count of HEVs or PHEVs across datasets")  graphregion(color(white))  
	graph export "${EFMPFleetRes}/Data_Check/counts_E5_vs_E1to4_HEV_PHEV.png", replace

	scatter countE5_HEV_PHEV countE1to4_HEV_PHEV if regexm(make, "PRIUS") == 0, title("Count of HEVs or PHEVs across datasets")  graphregion(color(white))  ///
	note("Excludes Priuses")
	graph export "${EFMPFleetRes}/Data_Check/counts_E5_vs_E1to4_HEV_PHEV_noPrius.png", replace
	gen E1overE5_HEV_PHEV = countE1to4_HEV_PHEV/countE5_HEV_PHEV
	gen E1overE5_BEV_PHEV = countE1to4_BEV_PHEV/countE5_BEV_PHEV
	la var countE5_HEV_PHEV "Count of HEV or PHEV in E5"
	la var countE5_BEV_PHEV "Count of BEV or PHEV in E5"
	la var countE1to4_HEV "Count of HEV in E1-4"
	la var countE1to4_BEV "Count of BEV in E1-4"
	la var countE1to4_PHEV "Count of PHEV in E1-4"
	la var shPHEV_in_HEV_PHEV "PHEV (E1-4) /HEV+PHEV (E5)"
	la var shBEV_in_BEV_PHEV "BEV (E1-4) /BEV+PHEV (E5)"
	la var E1overE5_BEV_PHEV "BEV+PHEV (E1-4) / BEV+PHEV (E5)"
	gen EV = PHEV_or_BEV == 1
	gen Hybrid = PHEV_or_HEV == 1 
	gen Diesel = 0
	save "${EFMPFleetData}/premerge_MPG_PHEV_HEV_BEV_Check.dta", replace

	keep year make model modelyr quarter PHEV_or_HEV PHEV_or_BEV shPHEV_in_HEV_PHEV shBEV_in_BEV_PHEV
	save "${EFMPFleetData}/PHEV_BEV_HEV_shares.dta", replace
restore


// create fuel type indicator. Set to 0 if missing fuel info.
gen EV = fuel == "Electric"
gen Diesel = fuel == "Diesel"
gen Hybrid = fuel == "Hybrid"
sort year quarter make model modelyr tract EV Diesel Hybrid

drop fuel
ren cnt_total cnt_mmy
foreach countvar in cnt_pricepresent cnt_mmy cnt_odometerpresent {
	ren `countvar' F`countvar'
	by year quarter make model modelyr tract EV Diesel Hybrid: egen `countvar' = total(F`countvar')
	replace  F`countvar' =  F`countvar'/`countvar'
}


// modify model names
replace model = "SIERRA 1500" if make == "GMC" & regexm(model, "SIERRA") == 1 & regexm(model, "1500")
replace model = "SIERRA 2500" if make == "GMC" & regexm(model, "SIERRA") == 1 & regexm(model, "2500")
replace model = "SIERRA 3500" if make == "GMC" & regexm(model, "SIERRA") == 1 & regexm(model, "3500")

replace model = subinstr(model, "-SERIES", " SERIES", .) if make == "BMW"


replace avg_price = avg_price * Fcnt_pricepresent
replace avg_odometer = avg_odometer * Fcnt_odometerpresent
replace percent_leased = percent_leased * Fcnt_mmy
drop Fcnt* censustract_hold month
gcollapse (sum) avg_price avg_odometer percent_leased, by(year quarter make model modelyr EV Diesel Hybrid tract cnt*)
sort make model modelyr EV Diesel Hybrid
save "${EFMPFleetData}/mmy_tract_quarter_pre_fueleconomy.dta", replace


// fueleconomy.gov data
	import delimited using "${EFMPFleetData}/vehicles/vehicles.csv", clear varnames(1)
	gen EV = atvtype == "EV"
	gen Diesel = fueltype == "Diesel" | atvtype == "Diesel"
	gen Hybrid = atvtype == "Hybrid" | atvtype == "Plug-in Hybrid"
	gen PHEV = atvtype == "Plug-in Hybrid"
	keep make model year comb08 EV Diesel Hybrid PHEV
	replace make = upper(trim(make))
	replace model = upper(trim(model))
	replace make = "MCLAREN" if make == "MCLAREN AUTOMOTIVE"
	ren year modelyr
	gen gpm = 1/comb08
	ren comb08 mpg 
	replace model = "PRIUS" if model == "PRIUS PLUG-IN HYBRID"
	replace model = "I3" if make == "BMW" & regexm(model, "I3") == 1
	replace EV = 1 if  model == "I3" & make == "BMW"
	replace Hybrid = 0 if  model == "I3" & make == "BMW"
	replace model = "SONATA" if regexm(model, "SONATA") == 1 & make == "HYUNDAI"
	replace model = "FUSION" if regexm(model, "FUSION") == 1 & make == "FORD"
	replace model = "C-MAX" if regexm(model, "C-MAX") == 1 & make == "FORD"
	replace model = "ACCORD" if regexm(model, "ACCORD") == 1 & make == "HONDA"
	gen HEV = Hybrid == 1 & PHEV != 1
	gen BEV = EV == 1 & PHEV != 1

	foreach type in BEV PHEV HEV {
		foreach var in mpg gpm {
			bys make model modelyr EV Diesel Hybrid: egen t_`var'_`type' = mean(`var') if `type' == 1
			bys make model modelyr EV Diesel Hybrid: egen `var'_`type' = mode(t_`var'_`type')
			drop t_*
		}
	}
	drop PHEV HEV BEV
	gcollapse gpm* mpg*, by(make model modelyr EV Diesel Hybrid)
	gisid make model modelyr EV Diesel Hybrid
	order make model modelyr EV Diesel Hybrid mpg* gpm*
	sort make model modelyr EV Diesel Hybrid
	save "${EFMPFleetData}/fueleffMMY.dta", replace
	
use  "${EFMPFleetData}/premerge_MPG_PHEV_HEV_BEV_Check.dta", clear

merge m:1 make model modelyr EV Diesel Hybrid using "${EFMPFleetData}/fueleffMMY.dta"
keep if _merge == 3
drop _merge	
la var mpg "MPG"
la var mpg_HEV "MPG HEV"
la var mpg_PHEV "MPG PHEV"
la var mpg_BEV "MPG BEV"
export excel make model modelyr year quarter countE5_HEV_PHEV countE1to4_HEV countE1to4_PHEV shPHEV_in_HEV_PHEV mpg mpg_HEV mpg_PHEV if PHEV_or_HEV == 1 ///
	using "${EFMPFleetRes}/Data_Check/PHEV_or_HEV_MMMYs.xlsx", replace firstrow(varlabel)
	
export excel make model modelyr year quarter countE5_BEV_PHEV countE1to4_BEV countE1to4_PHEV shBEV_in_BEV_PHEV E1overE5_BEV_PHEV mpg mpg_BEV mpg_PHEV if PHEV_or_BEV == 1 ///
	using "${EFMPFleetRes}/Data_Check/PHEV_or_BEV_MMMYs.xlsx", replace firstrow(varlabel)
	
// now just keep relevant variables and prep for merge
use  "${EFMPFleetData}/premerge_MPG_PHEV_HEV_BEV_Check.dta", clear
keep make model modelyr EV Hybrid Diesel year quarter shPHEV_in_HEV_PHEV shBEV_in_BEV_PHEV
gduplicates drop
tempfile shareMMMY
save `shareMMMY', replace


// merge fuel efficiency data for the first time
use "${EFMPFleetData}/mmy_tract_quarter_pre_fueleconomy.dta", clear
// merge the share variables
merge m:1 make model modelyr EV Diesel Hybrid year quarter using `shareMMMY', keep(1 3) nogen
// merge the fuel efficiency data
merge m:1 make model modelyr EV Diesel Hybrid using "${EFMPFleetData}/fueleffMMY.dta"



// format model string to match mmys that were unmatched in the initial merge. 
preserve
	keep if _merge == 2
	foreach drive in AWD FWD 4WD 2WD {
		replace model = subinstr(model, "`drive'", "", .)
		replace model = trim(model)
	}
	keep make model modelyr mpg gpm EV Diesel Hybrid 
	gduplicates drop
	gcollapse gpm mpg, by(make model modelyr EV Diesel Hybrid)
	ren gpm gpm_v2
	ren mpg mpg_v2
	tempfile merge2
	save `merge2', replace
restore
drop if _merge == 2


foreach drive in AWD FWD 4WD 2WD {
	replace model = subinstr(model, "`drive'", "", .) if  _merge == 1
	replace model = trim(model) if  _merge == 1
}
merge m:1 make model modelyr EV Diesel Hybrid using `merge2', gen(_merge_v2)

replace gpm = gpm_v2 if _merge == 1 & _merge_v2 == 3
replace mpg = mpg_v2 if _merge == 1 & _merge_v2 == 3

replace mpg = mpg_v2 if _merge_v2 == 2
replace gpm = gpm_v2 if _merge_v2 == 2
drop mpg_v2 gpm_v2
tab _merge _merge_v2, mi


preserve
	replace _merge = 3 if _merge_v2 == 3
	replace _merge = 2 if _merge_v2 == 2 & mi(_merge)
	bys make model modelyr EV Diesel Hybrid: gegen totaltrans = total(cnt_mmy)
	bys make model modelyr EV Diesel Hybrid: gen N = _N
	replace N = . if _merge == 2
	keep make model modelyr EV Diesel Hybrid _merge N totaltrans mpg gpm
	gduplicates drop 
	sort make modelyr model
	
	la var N "number of mmy-tracts"
	la var totaltrans "total transactions for the MMY"
	la var _merge "status after 2 merges (as is and taking away WDs)"
	la var make "make"
	la var model "model"
	la var modelyr "model year"
	la var EV "1 if EV"
	la var Diesel "1 if diesel"
	la var Hybrid "1 if hybrid"
	save "${EFMPFleetData}/mmy_matching_pre.dta", replace
	keep if _merge != 3 

	gen model_mod = model
	
	replace make = "GMC" if make == "GENERAL MOTORS"
	// Acura:
	replace model_mod = "CL" if regexm(make, "Acura") == 1 & regexm(model_mod, "CL") == 1
	replace model_mod = "CL" if regexm(make, "Acura") == 1 & regexm(model_mod, "TL") == 1 & regexm(model_mod, "TLX") != 1

	replace model_mod = subinstr(model_mod, " AWD", "", .) if regexm(make, "ACURA") == 1 
	replace model_mod = subinstr(model_mod, " FWD", "", .) if regexm(make, "ACURA") == 1 
	replace model_mod = subinstr(model_mod, " 4WD", "", .) if regexm(make, "ACURA") == 1 
	replace model_mod = subinstr(model_mod, " 2WD", "", .) if regexm(make, "ACURA") == 1 
	replace model_mod = subinstr(model_mod, " HYBRID", "", .) if regexm(make, "ACURA") == 1  // this is OK because we still match on MMY plus engine type.
	replace model_mod = subinstr(model_mod, " A-SPEC", "", .) if regexm(make, "ACURA") == 1 
	replace model_mod = subinstr(model_mod, "NSX-T", "NSX", .) if regexm(make, "ACURA") == 1 
	replace model_mod = subinstr(model_mod, "TL-SERIES", "TL", .) if regexm(make, "ACURA") == 1 

	// Aston Martin
	replace model_mod = subinstr(model_mod, "DB-7", "DB7", .) if regexm(make, "ASTON MARTIN") == 1
	
	replace model_mod = model_mod + "." if regexm(make, "ASTON MARTIN") == 1
	replace model_mod = subinstr(model_mod, " S.", "", .) if regexm(make, "ASTON MARTIN") == 1
	replace model_mod = subinstr(model_mod, ".", "", .) if regexm(make, "ASTON MARTIN") == 1
	replace model_mod = "DB7" if regexm(model_mod, "DB7") == 1
	
	replace model_mod = "DB9" if regexm(model_mod, "DB9") == 1 & regexm(make, "ASTON MARTIN") == 1 
	replace model_mod = "VANTAGE" if model_mod == "V8 VANTAGE" & regexm(make, "ASTON MARTIN") == 1 
	replace model_mod = "DBS" if regexm(model_mod, "DBS") == 1 & regexm(make, "ASTON MARTIN") == 1 
	replace model_mod = "VANTAGE" if model_mod == "V12 VANTAGE" & regexm(make, "ASTON MARTIN") == 1 
	replace model_mod = "DB11" if regexm(model_mod, "DB11") == 1 & regexm(make, "ASTON MARTIN") == 1 
	
	// Audi
	replace model_mod = subinstr(model_mod, "TTS", "TT", .) if regexm(make, "AUDI") == 1 
	foreach str in A3 A5 A6 A7 A8 ALLROAD R8 RS3 RS5 RS7 S4 S6 S8 TT {
		replace model_mod = "`str'" if regexm(model_mod, "`str'") == 1 & regexm(make, "AUDI") == 1 
	}

	
	// BMW
	* numbered series, Z series (Z3, Z4 etc), Alpina, X series (X3, 4, 5 etc), M series (M1, 3 5)
	foreach str in CONVERTIBLE TOURING LUXURY {
		drop if regexm(make, "BMW") == 1 & regexm(model_mod, "`str'") & regexm(model_mod, "^M") != 1
	}
	drop if regexm(make, "BMW") == 1 & regexm(model_mod, "SPORT WAGON")
	foreach str in COUPE XDRIVE ROADSTER {
		replace model_mod = subinstr(model_mod, "`str'", "", .) if regexm(make, "BMW") == 1 
	}
	replace model_mod = subinstr(model_mod, "/", " ", .) if regexm(make, "BMW") == 1
	split model_mod, p(" ") generate(temp)
	replace model_mod = temp1 if regexm(make, "BMW") == 1

	replace model_mod = subinstr(model_mod, "-SERIES", "", .) if regexm(make, "BMW") == 1
	forvalues i = 1/8 {
		replace model_mod = "`i'" if regexm(model_mod, "^`i'") == 1 & regexm(make, "BMW") == 1
		replace model_mod = "M`i'" if regexm(model_mod, "^M`i'") == 1 & regexm(make, "BMW") == 1

	}
	replace model_mod = subinstr(model_mod, "ACTIVEHYBRID", "", .) if regexm(make, "BMW") == 1 
	replace model_mod = trim(model_mod)
	drop temp*
	
	// Bentley, Bugatti 
	split model_mod, p(" ") generate(temp)
	replace model_mod = temp1 if regexm(make, "Bentley") == 1 | regexm(make, "Bugatti") == 1 
	drop temp*
	
	// Buick
	replace model_mod = "REGAL/CENTURY" if regexm(make, "Buick") == 1 & (model_mod == "REGAL" | model_mod == "CENTURY") & modelyr == 1997
	replace model_mod = "LACROSSE/ALLURE" if regexm(make, "Buick") == 1 & (model_mod == "LACROSSE" | model_mod == "ALLURE")
	foreach type in AWD FWD 2WD {
		replace model_mod = subinstr(model_mod, " `type'", "", .) if regexm(make, "Buick") == 1
	}
	
	// CADILLAC
	foreach type in AWD ESV EXT 2WD SEDAN {
		replace model_mod = subinstr(model_mod, " `type'", "", .) if make == "Cadillac"
	}
	replace model_mod = "ESCALADE" if model_mod == "ESCALADE~ESCALADE EXT" & make == "Cadillac"
	replace model_mod = "DEVILLE" if model_mod == "DEVILLE/CONCOURSE" & make == "Cadillac" & inlist(modelyr, 1994, 1995) == 1
	replace model_mod = "FLEETWOOD/DEVILLE" if (model_mod == "DEVILLE" | model_mod == "CONCOURSE") & make == "Cadillac" & modelyr == 1992
	replace model_mod = "DEVILLE" if model_mod == "DEVILLE/60 SPECIAL" & make == "Cadillac" & modelyr == 1993
	
	// Chevrolet
	* what to do with G1500/2500/3500 vans? in using they are probably named "VAN 1500/2500 AWD" or 2WD
	replace model_mod = subinstr(model_mod, "CITY EXPRESS", "CITYEXPRESS", .) if make == "CHEVROLET"
	replace model_mod = subinstr(model_mod, "EXPRESS 1500", "EXPRESS1500", .) if make == "CHEVROLET"
	replace model_mod = subinstr(model_mod, "EXPRESS 2500", "EXPRESS2500", .) if make == "CHEVROLET"
	replace model_mod = subinstr(model_mod, "EXPRESS 3500", "EXPRESS3500", .) if make == "CHEVROLET"
	replace model_mod = subinstr(model_mod, "G10/20", "G10", .) if make == "CHEVROLET"
	
	replace model_mod = "C1500" if (regexm(model_mod, "C/K1500") == 1 | regexm(model_mod, "K1500") == 1 | regexm(model_mod, "C1500") == 1 ) & make == "CHEVROLET" 
	replace model_mod = "C2500" if (regexm(model_mod, "C/K2500") == 1 | regexm(model_mod, "K2500") == 1 | regexm(model_mod, "C2500") == 1 ) & make == "CHEVROLET" 
	replace model_mod = "C3500" if (regexm(model_mod, "C/K3500") == 1 | regexm(model_mod, "K3500") == 1 | regexm(model_mod, "C3500") == 1 ) & make == "CHEVROLET" 
	
	foreach modelstring in ASTRO AVALANCHE AVEO BLAZER C1500 C2500 C3500 CAPRICE CAPTIVA CITYEXPRESS COBALT EXPRESS1500 EXPRESS2500 EXPRESS3500 G10 G1500 G2500 G20 G30 G3500 K20 LUMINA MALIBU S10 SPARK SSR SUBURBAN TAHOE {
		replace model_mod = "`modelstring'" if regexm(model_mod, "`modelstring'") == 1 & make == "CHEVROLET"
	}
	replace model_mod = "SILVERADO 1500" if regexm(model_mod, "SILVERADO 15") == 1 & make == "CHEVROLET"	
	replace model_mod = "SILVERADO 2500" if regexm(model_mod, "SILVERADO 25") == 1 & make == "CHEVROLET"
	replace model_mod = "SILVERADO 3500" if regexm(model_mod, "SILVERADO 35") == 1 & make == "CHEVROLET"
	replace model_mod = "SILVERADO C15" if (regexm(model_mod, "SILVERADO CLASSIC 15") == 1 | regexm(model_mod, "SILVERADO C15") == 1) & make == "CHEVROLET"
	replace model_mod = "SILVERADO C25" if (regexm(model_mod, "SILVERADO CLASSIC 25") == 1 | regexm(model_mod, "SILVERADO C25") == 1) & make == "CHEVROLET"
	replace model_mod = "SILVERADO C35" if (regexm(model_mod, "SILVERADO CLASSIC 35") == 1 | regexm(model_mod, "SILVERADO C35") == 1) & make == "CHEVROLET"

	// CHRYSLER
	replace model_mod = "NEW YORKER" if regexm(model_mod, "NEW YORKER") == 1 & make == "CHRYSLER"
	replace model_mod = "TOWN & COUNTRY" if (regexm(model_mod, "TOWN & COUNTRY") == 1 | regexm(model_mod, "TOWN AND COUNTRY") == 1) & make == "CHRYSLER"
	foreach namestring in 300 ASPEN CONCORDE CROSSFIRE LEBARON PACIFICA SEBRING {
		replace model_mod = "`namestring'" if regexm(model_mod, "`namestring'") == 1 & make == "CHRYSLER"
	}
	// DODGE
	replace model_mod = "B150 VAN" if regexm(model_mod, "^B150") == 1 & regexm(model_mod, "VAN") == 1 & 	make == "DODGE"
	replace model_mod = "B250 VAN" if regexm(model_mod, "^B250") == 1 & regexm(model_mod, "VAN") == 1 & 	make == "DODGE"
	replace model_mod = "B350 VAN" if regexm(model_mod, "^B350") == 1 & regexm(model_mod, "VAN") == 1 & 	make == "DODGE"

	replace model_mod = "AD150 RAMCHARGER" if regexm(model_mod, "AD150 RAMCHARGER") == 1 & make == "DODGE"

	replace model_mod = "CARAVAN" if regexm(model_mod, "CARAVAN") == 1 & make == "DODGE"
	
	replace model_mod = "D250" if regexm(model_mod, "^D250") == 1 & make == "DODGE"
	replace model_mod = "DAKOTA" if regexm(model_mod, "DAKOTA") == 1 & make == "DODGE"
	replace model_mod = "DURANGO" if regexm(model_mod, "DURANGO") == 1 & make == "DODGE"
	replace model_mod = "NEON" if regexm(model_mod, "NEON") == 1 & make == "DODGE"

	replace model_mod = subinstr(model_mod, "PICKUP", "VAN", .) if regexm(model_mod, "RAM") == 1 & make == "DODGE"
	replace model_mod = "1500 RAM VAN" if regexm(model_mod, "RAM VAN") == 1 & regexm(model_mod, "1500") == 1 & 	make == "DODGE"
	replace model_mod = "2500 RAM VAN" if regexm(model_mod, "RAM VAN") == 1 & regexm(model_mod, "2500") == 1 & 	make == "DODGE"
	replace model_mod = "3500 RAM VAN" if regexm(model_mod, "RAM VAN") == 1 & regexm(model_mod, "3500") == 1 & 	make == "DODGE"

	replace model_mod = "1500 RAM WAGON" if regexm(model_mod, "RAM WAGON") == 1 & regexm(model_mod, "1500") == 1 & 	make == "DODGE"
	replace model_mod = "2500 RAM WAGON" if regexm(model_mod, "RAM WAGON") == 1 & regexm(model_mod, "2500") == 1 & 	make == "DODGE"
	replace model_mod = "3500 RAM WAGON" if regexm(model_mod, "RAM WAGON") == 1 & regexm(model_mod, "3500") == 1 & 	make == "DODGE"
	
	replace model_mod = "1500 RAM WAGON" if regexm(model_mod, "RAM") == 1 & regexm(model_mod, "VAN") != 1 & regexm(model_mod, "150") == 1 & 	make == "DODGE"
	replace model_mod = "2500 RAM WAGON" if regexm(model_mod, "RAM") == 1 & regexm(model_mod, "VAN") != 1 & regexm(model_mod, "250") == 1 & 	make == "DODGE"
	replace model_mod = "3500 RAM WAGON" if regexm(model_mod, "RAM") == 1 & regexm(model_mod, "VAN") != 1 & regexm(model_mod, "350") == 1 & 	make == "DODGE"

	replace model_mod = "RAM 50" if regexm(model_mod, "RAM 50") == 1 & make == "DODGE"
	
	replace model_mod = "1500 SPRINTER WAGON" if regexm(model_mod, "SPRINTER") == 1 & regexm(model_mod, "1500") == 1 & 	make == "DODGE"
	replace model_mod = "2500 SPRINTER WAGON" if regexm(model_mod, "SPRINTER") == 1 & regexm(model_mod, "2500") == 1 & 	make == "DODGE"
	replace model_mod = "3500 SPRINTER WAGON" if regexm(model_mod, "SPRINTER") == 1 & regexm(model_mod, "3500") == 1 & 	make == "DODGE"

	replace model_mod = "STRATUS" if regexm(model_mod, "STRATUS") == 1 & make == "DODGE"
	replace model_mod = "VIPER" if regexm(model_mod, "VIPER") == 1 & make == "DODGE"
	// FERRARI
	foreach namestring in 348 360 430 456 512 575 599 612 F355 CHALLENGE ENZO LAFERRARI MONDIAL {
		replace model_mod = "`namestring'" if regexm(model_mod, "`namestring'") == 1 & make == "FERRARI"
	}
	replace model_mod = "F12 BERLINETTA" if regexm(model_mod, "F12BERLINETTA") == 1 & make == "FERRARI"
	replace model_mod = "F12 TDF" if regexm(model_mod, "F12 =TDF") == 1 & make == "FERRARI"

	// FIAT
	replace model_mod = "124 SPIDER" if regexm(model_mod, "124/SPIDER") == 1 & make == "FIAT"
	replace model_mod = "500C" if regexm(model_mod, "500 CABRIO") == 1 & make == "FIAT"
	replace model_mod = "500L" if regexm(model_mod, "500 L") == 1 & make == "FIAT"
	replace model_mod = "500X" if regexm(model_mod, "500 X") == 1 & make == "FIAT"

	//FORD
	replace model_mod = "AEROSTAR" if regexm(model_mod, "AEROSTAR") == 1 & make == "FORD"
	replace model_mod = "C-MAX" if regexm(model_mod, "C-MAX") == 1 & make == "FORD"
	replace model_mod = "CROWN VICTORIA" if regexm(model_mod, "CROWN VICTORIA") == 1 & make == "FORD"
	* here we'd ideally like to distinguish between vans and wagons.
	replace model_mod = "E150" if regexm(model_mod, "^E150") == 1 & make == "FORD"
	replace model_mod = "E250" if regexm(model_mod, "^E250") == 1 & make == "FORD"
	replace model_mod = "E350" if regexm(model_mod, "^E350") == 1 & make == "FORD"
	
	foreach namestring in ESCAPE ESCORT EXCURSION EXPEDITION EXPLORER FOCUS FREESTAR FUSION RANGER  {
	replace model_mod = "`namestring'" if regexm(model_mod, "`namestring'") == 1 & make == "FORD"
	}
	replace model_mod = "ESCORT" if regexm(model_mod, "ESCORT") == 1 & make == "FORD"

	replace model_mod = "F150" if regexm(model_mod, "^F150") == 1 & make == "FORD"
	replace model_mod = "F250" if regexm(model_mod, "^F250") == 1 & make == "FORD"
	replace model_mod = "F350" if regexm(model_mod, "^F350") == 1 & make == "FORD"
	
	replace model_mod = "TRANSIT 150" if regexm(model_mod, "TRANSIT") == 1 & regexm(model_mod, "150") == 1 & make == "FORD"
	replace model_mod = "TRANSIT 250" if regexm(model_mod, "TRANSIT") == 1 & regexm(model_mod, "250") == 1 & make == "FORD"
	replace model_mod = "TRANSIT 350" if regexm(model_mod, "TRANSIT") == 1 & regexm(model_mod, "350") == 1 & make == "FORD"
	
	replace model_mod = "WINDSTAR VANS" if regexm(model_mod, "WINDSTAR") == 1 & regexm(model_mod, "VAN") == 1 & make == "FORD"
	
	// GEO
	replace model_mod = "TRACKER" if regexm(model_mod, "TRACKER") == 1 & make == "GEO"
	//GMC
	replace model_mod = "C/K1500" if regexm(model_mod, "^C15") == 1 & make == "GMC"
	replace model_mod = "C/K1500" if regexm(model_mod, "^K15") == 1 & make == "GMC"
	replace model_mod = "C/K2500" if regexm(model_mod, "^C25") == 1 & make == "GMC"
	replace model_mod = "C/K2500" if regexm(model_mod, "^K25") == 1 & make == "GMC"
	replace model_mod = "C/K3500" if regexm(model_mod, "^C35") == 1 & make == "GMC"
	replace model_mod = "C/K3500" if regexm(model_mod, "^K35") == 1 & make == "GMC"

	replace model_mod = "G15/25" if regexm(model_mod, "^G15/25") == 1 & make == "GMC"
	replace model_mod = "G15/25" if regexm(model_mod, "^G15") == 1 & make == "GMC"
	replace model_mod = "G15/25" if regexm(model_mod, "^G25") == 1 & make == "GMC"
	replace model_mod = "G35" if regexm(model_mod, "^G35") == 1 & make == "GMC"

	replace model_mod = "JIMMY" if regexm(model_mod, "^JIMMY") == 1 & make == "GMC"
	replace model_mod = "S15" if regexm(model_mod, "^S15") == 1 & make == "GMC"
	replace model_mod = "SAFARI" if regexm(model_mod, "^SAFARI") == 1 & regexm(model_mod, "PASSENGER") == 1 & make == "GMC"
	replace model_mod = "SAFARI" if regexm(model_mod, "^SAFARI") == 1 & (regexm(model_mod, "CONVERSION") == 1 | regexm(model_mod, "CARGO") == 1) & make == "GMC"
	replace model_mod = "SAVANA 1500" if regexm(model_mod, "SAVANA 1500") == 1 & make == "GMC"
	replace model_mod = "SAVANA 2500" if regexm(model_mod, "SAVANA 2500") == 1 & make == "GMC"
	replace model_mod = "SAVANA 3500" if regexm(model_mod, "SAVANA 3500") == 1 & make == "GMC"
	replace model_mod = "SIERRA 15" if regexm(model_mod, "SIERRA") == 1 & regexm(model_mod, "15") == 1 & make == "GMC"
	replace model_mod = "SIERRA 25" if regexm(model_mod, "SIERRA") == 1 & regexm(model_mod, "25") == 1 & make == "GMC"
	replace model_mod = "SIERRA 35" if regexm(model_mod, "SIERRA") == 1 & regexm(model_mod, "35") == 1 & make == "GMC"
	replace model_mod = "SUBURBAN" if regexm(model_mod, "^SUBURBAN") == 1 & make == "GMC"
	replace model_mod = "T15 JIMMY" if regexm(model_mod, "^T15") == 1 & regexm(model_mod, "JIMMY") == 1 & make == "GMC"
	replace model_mod = "YUKON" if regexm(model_mod, "YUKON") == 1 & regexm(model_mod, "XL") != 1 & make == "GMC"
	replace model_mod = "YUKON XL" if regexm(model_mod, "YUKON") == 1 & regexm(model_mod, "XL") == 1 & make == "GMC"

	//HONDA
	foreach namestring in ACCORD CIVIC CLARITY FIT RIDGELINE {
		replace model_mod = "`namestring'" if regexm(model_mod, "`namestring'") == 1 & regexm(model_mod, "CNG") != 1 & make == "HONDA"
	}
	
	
	// HYUNDAI
	foreach namestring in ACCENT ELENTRA GENESIS IONIQ SONATA TUCSON {
		replace model_mod = "`namestring'" if regexm(model_mod, "`namestring'") == 1 & make == "HYUNDAI"
	}
	replace model_mod = "SANTA FE XL" if regexm(model_mod, "SANTA FE XL") == 1 & make == "HYUNDAI"

	// INFINITI
	replace model_mod = "G37" if regexm(model_mod, "G37") == 1 & regexm(model_mod, "G37X") != 1 & make == "INFINITI"
	replace model_mod = "G37X" if regexm(model_mod, "G37X") == 1 & make == "INFINITI"
	foreach namestring in JX Q50 Q60 Q70 QX60 {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & make == "INFINITI"
	}
	// ISUZU
	foreach namestring in ASCENDER HOMBRE I-280 I-290 I-350 I-370 {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & make == "ISUZU"
	}
	// JAGUAR
	replace model_mod = "S-TYPE" if regexm(model_mod, "X200 S-TYPE") == 1 & make == "JAGUAR"
	replace model_mod = "XJ" if regexm(model_mod, "^XJ") == 1 & regexm(model_mod, "^XJL") != 1 & ///	
		regexm(model_mod, "^XJR") != 1 & regexm(model_mod, "^XJS") != 1 & make == "JAGUAR"

	foreach namestring in F-TYPE S-TYPE VDP XJRS XK {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & make == "JAGUAR"
	}
	// JEEP
	foreach namestring in COMANCHE LIBERTY WRANGLER {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & make == "JEEP"
	}
	// KIA
	foreach namestring in FORTE OPTIMA RIO SEPHIA SOUL SPECTRA  {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & make == "KIA"
	}
	// LAMBORGHINI
	foreach namestring in AVENTADOR DIABLO GALLARDO MURCIELADGO {
		replace model_mod = "`namestring'" if regexm(model_mod, "`namestring'") == 1 & make == "LAMBORGHINI"
	}
	// LAND ROVER
	foreach namestring in DISCOVERY FREELANDER {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & make == "LAND ROVER"
	}
	replace model_mod = "RANGE ROVER" if regexm(model_mod, "RANGE ROVER") == 1 &  regexm(model_mod, "RANGE ROVER SPORT") != 1 & make == "LAND ROVER"
	replace model_mod = "RANGE ROVER SPORT" if regexm(model_mod, "RANGE ROVER SPORT") == 1 & make == "LAND ROVER"

	// LEXUS
	foreach namestring in CT ES GS GX HS IS LC LS LX NX RC RX SC UX {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & make == "LEXUS"
	}	
	// LINCOLN
	foreach namestring in MKZ NAVIGATOR {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & make == "LINCOLN"
	}	
	
	replace model_mod = "TOWN CAR" if regexm(model_mod, "TOWN CAR") == 1 & make == "LINCOLN"

	// LOTUS
	replace model_mod = "ELISE" if regexm(model_mod, "ELISE") == 1 & make == "LOTUS"
	replace model_mod = "ELISE" if regexm(model_mod, "EXIGE") == 1 & make == "LOTUS"
	replace model_mod = "ESPRIT" if regexm(model_mod, "ESPRIT") == 1 & make == "LOTUS"

	// MASERATI
	replace model_mod = "SPYDER" if regexm(model_mod, "^SPIDER") == 1 & make == "MASERATI"
	foreach namestring in COUPLE GHIBLI GRANSPORT M128 QUATTROPORTE SPYDER {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & make == "MASERATI"
	}	
	
	// MAYBACH
	replace model_mod = "LANDAULET" if regexm(model_mod, "^LANDAULET") == 1 & make == "MAYBACH"
	replace model_mod = subinstr(model_mod, "SERIES ", "", .) if make == "MAYBACH"
	
	// MAZDA
	replace model_mod = "MX-3" if regexm(model_mod, "^MX-3") == 1 & make == "MAZDA"
	replace model_mod = "MX-3" if regexm(model_mod, "^MX3") == 1 & make == "MAZDA"
	replace model_mod = "MX-5" if regexm(model_mod, "^MX-5") == 1 & make == "MAZDA"
	replace model_mod = "MX-5" if regexm(model_mod, "^MX-5") == 1 & make == "MAZDA"
	replace model_mod = "MX-5" if regexm(model_mod, "^MIATA") == 1 & make == "MAZDA"
	replace model_mod = "MX-6" if regexm(model_mod, "^MX6") == 1 & make == "MAZDA"
	replace model_mod = "RX-7" if regexm(model_mod, "^RX7") == 1 & make == "MAZDA"
	replace model_mod = "RX-8" if regexm(model_mod, "^RX8") == 1 & make == "MAZDA"

	
	foreach namestring in 626 B2200 B2500 B2600 B3000 B4000 PROTEGE TRIBUTE  {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & make == "MAZDA"
	}	
	// MERCEDES-BENZ
	replace model_mod = subinstr(model_mod, " SERIES", "", .) if make == "MERCEDES-BENZ"
	replace model_mod = subinstr(model_mod, " CLASS", "", .) if make == "MERCEDES-BENZ"
	
	foreach namestring in 190 300 400 500 600   {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & make == "MERCEDES-BENZ"
	}
	replace model_mod = "AMG GT" if regexm(model_mod, "^AMG GT") == 1 & make == "MERCEDES-BENZ"
	replace model_mod = "B" if regexm(model_mod, "^B") == 1 & make == "MERCEDES-BENZ"
	
	forvalues i = 2/6 {
		replace model_mod = "C" if regexm(model_mod, "^C`i'") == 1 & make == "MERCEDES-BENZ"
		replace model_mod = "CL" if regexm(model_mod, "^CL`i'") == 1 & make == "MERCEDES-BENZ"
		replace model_mod = "CLA" if regexm(model_mod, "^CLA`i'") == 1 & make == "MERCEDES-BENZ"
		replace model_mod = "CLK" if regexm(model_mod, "^CLK`i'") == 1 & make == "MERCEDES-BENZ"
		replace model_mod = "CLS" if regexm(model_mod, "^CLS`i'") == 1 & make == "MERCEDES-BENZ"
		replace model_mod = "E" if regexm(model_mod, "^E`i'") == 1 & make == "MERCEDES-BENZ"
		replace model_mod = "G" if regexm(model_mod, "^G`i'") == 1 & make == "MERCEDES-BENZ"
		replace model_mod = "GL" if regexm(model_mod, "^GL`i'") == 1 & make == "MERCEDES-BENZ"
		replace model_mod = "GLA" if regexm(model_mod, "^GLA`i'") == 1 & make == "MERCEDES-BENZ"
		replace model_mod = "GLC" if regexm(model_mod, "^GLC`i'") == 1 & make == "MERCEDES-BENZ"
		replace model_mod = "GLE" if regexm(model_mod, "^GLE`i'") == 1 & make == "MERCEDES-BENZ"
		replace model_mod = "GLK" if regexm(model_mod, "^GLK`i'") == 1 & make == "MERCEDES-BENZ"
		replace model_mod = "GLS" if regexm(model_mod, "^GLS`i'") == 1 & make == "MERCEDES-BENZ"
		replace model_mod = "M" if regexm(model_mod, "^ML`i'") == 1 & make == "MERCEDES-BENZ"
		replace model_mod = "R" if regexm(model_mod, "^R`i'") == 1 & make == "MERCEDES-BENZ"
		replace model_mod = "S" if regexm(model_mod, "^S`i'") == 1 & make == "MERCEDES-BENZ"
		replace model_mod = "SL" if regexm(model_mod, "^SL`i'") == 1 & make == "MERCEDES-BENZ"
		replace model_mod = "SLC" if regexm(model_mod, "^SLC`i'") == 1 & make == "MERCEDES-BENZ"
		replace model_mod = "SLK" if regexm(model_mod, "^SLK`i'") == 1 & make == "MERCEDES-BENZ"

	}
	replace model_mod = "METRIS" if regexm(model_mod, "^METRIS") == 1 & make == "MERCEDES-BENZ"
	replace model_mod = "SLS" if regexm(model_mod, "^SLS") == 1 & make == "MERCEDES-BENZ"

	replace model_mod = "SPRINTER 1500" if regexm(model_mod, "1500 SPRINTER") == 1 & make == "MERCEDES-BENZ"
	replace model_mod = "SPRINTER 2500" if regexm(model_mod, "2500 SPRINTER") == 1 & make == "MERCEDES-BENZ"
	replace model_mod = "SPRINTER 3500" if regexm(model_mod, "3500 SPRINTER") == 1 & make == "MERCEDES-BENZ"
	
	replace model_mod = "SPRINTER 1500" if regexm(model_mod, "^SPRINTER 1500") == 1 & make == "MERCEDES-BENZ"
	replace model_mod = "SPRINTER 1500" if regexm(model_mod, "^SPRINTER 2500") == 1 & make == "MERCEDES-BENZ"
	replace model_mod = "SPRINTER 1500" if regexm(model_mod, "^SPRINTER 3500") == 1 & make == "MERCEDES-BENZ"
	// MERCURY
	replace model_mod = "MARQUIS" if regexm(model_mod, "GRAND MARQUIS") == 1 & make == "MERCURY"
	foreach namestring in MARINER MARQUIS MILAN MONTEREY VILLAGER {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & make == "MERCURY"
	}
	// MINI
	** unclear how we should do this. they're almost all coopers, but there are a bunch of variants. Experian data doesnt specify
	replace model_mod = "COOPER" if regexm(model_mod, "COOPER") == 1 & make == "MINI"
	// MITSUBISHI
	foreach namestring in 3000GT DIAMANTE EXPO OUTLANDER RAIDER {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & make == "MITSUBISHI"
	}
	// NISSAN
	foreach namestring in 350Z ALTIMA LEAF MURANO PATHFINDER ROGUE SENTRA TITAN VERSA {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & make == "NISSAN"
	}
	replace model_mod = "NV 200" if model_mod == "NV200 CARGO VAN" & make == "NISSAN"
	
	// OLDSMOBILE
	replace model_mod = "88" if regexm(model_mod, "EIGHTY-EIGHT") == 1 & make == "OLDSMOBILE"
	replace model_mod = "98" if regexm(model_mod, "NINETY-EIGHT") == 1 & make == "OLDSMOBILE"
	foreach namestring in CIERA 88 {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & make == "OLDSMOBILE"
	}
	// PLYMOUTH
	replace model_mod = "VOYAGER" if regexm(model_mod, "GRAND VOYAGER") == 1 & make == "PLYMOUTH"
	replace model_mod = "SUNDANCE" if regexm(model_mod, "SUNDANCE") == 1 & make == "PLYMOUTH"

	// PONTIAC
	replace model_mod = "G5" if model_mod == "PURSUIT" & make == "PONTIAC"
	foreach namestring in FIREBIRD FIREFLY G3 G5 MONTANA WAVE {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & make == "PONTIAC"
	}
	// PORSCHE
	foreach namestring in 911 928 CAYENNE CAYMAN MACAN PANAMERA  {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & make == "PORSCHE"
	}
	// RAM
	replace model_mod = "C/V" if regexm(model_mod, "C/V") == 1 & make == "RAM"
	
	// ROLLS-ROYCE
	foreach namestring in CORNICHE SILVER  {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & make == "ROLLS-ROYCE"
	}
	// SAAB
	foreach namestring in 9-2X 9-3 9-5 900  {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & make == "SAAB"
	}
	
	// SATURN
	foreach namestring in ASTRA AURA L S VUE  {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & make == "SATURN"
	}
	// SMART
	replace model_mod = "FORTWO" if regexm(model_mod, "FORTWO") == 1 & make == "SMART"
	// SUBARU
	foreach namestring in CROSSTREK IMPREZA LEGACY LOYALE OUTBACKX XV {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & make == "SUBARU"
	}
	// SUZUKI
	foreach namestring in ESTEEM SAMURAL SIDEKICK SWIFT VITARA {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & make == "SUZUKI"
	}
	replace model_mod = "GRAND VITARA" if regexm(model_mod, "^GRAND VITARA") == 1 & make == "SUZUKI"
	// TESLA
	replace model_mod = "MODEL 3" if regexm(model_mod, "^MODEL 3") == 1 & make == "TESLA"
	replace model_mod = "MODEL S" if regexm(model_mod, "^MODEL S") == 1 & make == "TESLA"
	replace model_mod = "MODEL X" if regexm(model_mod, "^MODEL X") == 1 & make == "TESLA"
	replace model_mod = "ROADSTER" if regexm(model_mod, "^ROADSTER") == 1 & make == "TESLA"

	// TOYOTA
	foreach namestring in AVALON CAMRY HIGHLANDER PRIUS RAV4 {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & regexm(model_mod, "^CNG") != 1 & make == "TOYOTA"
	}
	replace model_mod = "LAND CRUISER" if regexm(model_mod, "^LAND CRUISER") == 1 & regexm(model_mod, "^CNG") != 1 & make == "TOYOTA"
	// VOLKSWAGEN
	replace model_mod = "GLI" if regexm(model_mod, "GLI") == 1 & make == "VOLKSWAGEN"
	replace model_mod = "GTI" if regexm(model_mod, "GTI") == 1 & make == "VOLKSWAGEN"
	replace model_mod = "CABRIO" if regexm(model_mod, "CABRIO") == 1 & make == "VOLKSWAGEN"
	replace model_mod = "PASSAT" if regexm(model_mod, "PASSAT") == 1 & make == "VOLKSWAGEN"

	foreach namestring in CORRADO EUROVAN GOLF JETTA TOUAREG {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & make == "VOLKSWAGEN"
	}
	// VOLVO
	replace model_mod = "S90" if regexm(model_mod, "S90") == 1 & make == "VOLVO"
	replace model_mod = "V90" if regexm(model_mod, "V90") == 1 & make == "VOLVO"
	foreach namestring in C30 C70 S60 S80 V60 XC60 XC90 {
		replace model_mod = "`namestring'" if regexm(model_mod, "^`namestring'") == 1 & make == "VOLVO"
	}
	bys make model_mod modelyr EV Diesel Hybrid: gegen gpm_v3 = mean(gpm)
	bys make model_mod modelyr EV Diesel Hybrid: gegen mpg_v3 = mean(mpg)

	keep make model modelyr EV Diesel Hybrid gpm_v3 mpg_v3
	tempfile merge3
	save `merge3', replace
restore
drop if _merge_v2 == 2 
merge m:1 make model modelyr EV Diesel Hybrid using `merge3', gen(_merge_v3)

replace mpg = mpg_v3 if mpg == . & _merge_v3 == 3
replace gpm = gpm_v3 if gpm == . & _merge_v3 == 3

** 	TEMPORARY: FIX THIS LINE BELOW WHEN 
drop if  _merge_v3 == 2
drop _merge _merge_v2 _merge_v3 mpg_v3 gpm_v3


// impute MPG
* first make sure the share variables dont go over 1. If so trim at 1.
replace shPHEV_in_HEV_PHEV = 1 if shPHEV_in_HEV_PHEV>1 & !mi(shPHEV_in_HEV_PHEV) == 1
replace shBEV_in_BEV_PHEV = 1 if shBEV_in_BEV_PHEV>1 & !mi(shBEV_in_BEV_PHEV) == 1
replace mpg = shPHEV_in_HEV_PHEV*mpg_PHEV + (1-shPHEV_in_HEV_PHEV)*mpg_HEV if !mi(shPHEV_in_HEV_PHEV) == 1 
replace gpm = shPHEV_in_HEV_PHEV*gpm_PHEV + (1-shPHEV_in_HEV_PHEV)*gpm_HEV if !mi(shPHEV_in_HEV_PHEV) == 1 
replace mpg = shBEV_in_BEV_PHEV*mpg_BEV + (1-shBEV_in_BEV_PHEV)*mpg_PHEV if !mi(shBEV_in_BEV_PHEV) == 1 
replace gpm = shBEV_in_BEV_PHEV*gpm_BEV + (1-shBEV_in_BEV_PHEV)*gpm_PHEV if !mi(shBEV_in_BEV_PHEV) == 1 

* create optimistic and pessimistic MPG/GPM measures in which we take the most fuel efficient/inefficient versions.
* choose BEV over PHEV, and PHEV over HEV if optimistic
* choose PHEV over BEV, and HEV over PHEV if pessimistic
foreach type in mpg gpm {
	gen `type'_optimistic = `type'_BEV if !mi(shBEV_in_BEV_PHEV) == 1 
	replace `type'_optimistic = `type'_PHEV if !mi(shPHEV_in_HEV_PHEV) == 1 
	replace `type'_optimistic = `type' if mi(`type'_optimistic) == 1
	
	gen `type'_pessimistic = `type'_PHEV if !mi(shBEV_in_BEV_PHEV) == 1
	replace `type'_pessimistic = `type'_HEV if !mi(shPHEV_in_HEV_PHEV) == 1 
	replace `type'_pessimistic = `type' if mi(`type'_pessimistic) == 1

}
// drop these variables.
drop *_HEV *_PHEV *_BEV

// robustness check: MPGs/GPMs dropping BMW I3
gen mpg_r2 = mpg if make != "BMW" & model != "I3"
gen gpm_r2 = gpm if make != "BMW" & model != "I3"



// collapse data into the tract quarter level
drop avg_odometer cnt_odometerpresent cnt_pricepresent 
bys tract quarter year: gegen temp_cnt_total = total(cnt_mmy) if !mi(mpg) == 1
bys tract quarter year: gegen cnt_total = max(temp_cnt_total)


drop temp_*



drop if mi(year)
drop if mi(tract)
drop if mi(quarter)

save "${EFMPFleetData}/Before_collapse_tract_quarter.dta", replace
local momentvar "cnt_mmy avg_price mpg gpm mpg_optimistic gpm_optimistic mpg_pessimistic gpm_pessimistic modelyr mpg_r2 gpm_r2"

gcollapse (mean) `momentvar' /*(sd) `sdvar'*/ [fw = cnt_mmy], by(tract quarter year cnt_total)

save "${EFMPFleetData}/After_collapse_tract_quarter.dta", replace

use "${EFMPFleetData}/After_collapse_tract_quarter.dta", clear

// EFMP Eligible Districts
// ----------------------------
** Import EFMP eligible districts
preserve
	use "${MapFiles}/CensusTract_to_AQMD_map.dta", clear
	keep if inlist(AQMD_ID, 24, 38)
	keep CensusTract
	rename CensusTract tract
	replace tract = substr(tract, 2, 10)
	gduplicates drop
	tempfile Eligible_AQMD
	save `Eligible_AQMD'
restore


** Merge Experian with EFMP eligible districts 
merge m:1 tract using `Eligible_AQMD', keep(matched master)
gen eligibleAQMD = _merge==3
drop _merge


// CalEnviroScreen (CES)
// ----------------------------
** Format CES score data
preserve

	** Import Census Tracts to Zip Codes map and save tempfile
	* this is an m:m correspondence between tract and zipcode. 
	import delimited "${MapFiles}/CA_Census_Tracts_to_ZIP_codes_2010.txt", clear
	tostring v1, format(%12.0f) generate(tract)
	tostring v2, generate(OwnerZipCode)
	tempfile ZipMap_temp
	save `ZipMap_temp', replace
	
	gsort tract -v3
	ren v3 area
	bys tract: gen n = _n

	drop v1 v2
	reshape wide area OwnerZipCode, i(tract) j(n)
	tempfile ZipMap_area
	save `ZipMap_area'
	
	use `ZipMap_temp', clear
	drop v1 v2 v3
	tempfile ZipMap
	save `ZipMap'

	** Import Disadvantaged Community (DAC) flags
	** rebate level data
	import excel using "${CVRPData}/CVRPStats.xlsx", clear firstrow
	tostring CensusTract , format(%12.0f) generate(tract)
	tostring ZIP, generate(OwnerZipCode)
	keep tract DACCensusTractFlag DACZIPCodeFlag OwnerZipCode 
	gduplicates drop

	** Merge DAC flags with ZipMap
	merge 1:1 OwnerZipCode tract using `ZipMap', nogen keep(2 3)
	
	** Fill in the DAC flags for the known zip codes
	tempvar zipflag
	bysort OwnerZipCode: gegen `zipflag' = mean(DACZIPCodeFlag)
	replace DACZIPCodeFlag = `zipflag' if missing(DACZIPCodeFlag)
	assert inlist(DACZIPCodeFlag, 1 , 0, .)

	** Fill in the DAC flags for the known tracts
	tempvar tractflag
	bysort tract: gegen `tractflag' = mean(DACCensusTractFlag)
	replace DACCensusTractFlag = `tractflag' if missing(DACCensusTractFlag)
	assert inlist(DACCensusTractFlag, 1 , 0, .)

	** Save DAC tempfile 
	tempfile PreCES
	save `PreCES'
	
	la var DACCensusTractFlag "DAC tract"
	la var DACZIPCodeFlag "DAC zip"
	tabout DACCensusTractFlag DACZIPCodeFlag using "${EFMPFleetDraft}/Tables/Tract_ZIP_crosstab.tex", replace cells(freq row) style(tex) 
	** Import CES scores
	import excel using "${EFMPFleetData}/CalEnviroScreen2_Scores_Full_Oct_2014.xlsx", clear firstrow
	rename ZIP CESZip
	tostring CensusTract , format(%12.0f) generate(tract)
	keep CESZip tract CES20Score 

	** Merge CES scores with DAC data and save tempfile
	merge 1:m tract using `PreCES'	
	*tempfile CES_Data
	*save `CES_Data'
	
	** Select zipcode level max CES
	destring CES20Score, replace ignore("NA")
	keep if !missing(CES20Score)
	drop _merge
	tempfile TractZip_pre
	save `TractZip_pre'
	
	gcollapse (max) MaxCES = CES20Score, by(OwnerZipCode)
	tempfile CES_ZIP
	save `CES_ZIP'
	
	use `TractZip_pre', clear
	drop CESZip CES20Score 
	gisid tract OwnerZipCode
	tempfile TractZipRobust
	save `TractZipRobust', replace
	
restore

** Merge Experian with CES score at zipcode and tract levels
merge m:1 tract using `ZipMap_area', keep(match master) nogen

reshape long OwnerZipCode area, i(tract quarter year) j(n)
drop if mi(OwnerZipCode)
drop n

merge m:1 tract OwnerZipCode using `TractZipRobust', keep(1 3) nogen


bys quarter year OwnerZipCode: gegen total_area = total(area)
gen share_area = area/total_area

cap ren cnt_mmy_M cnt_mmy 
cap ren avg_price_M avg_price
cap ren mpg_M mpg
cap ren gpm_M gpm
cap ren modelyr_M modelyr

local sharevars "cnt_total cnt_mmy avg_price mpg gpm modelyr mpg_optimistic mpg_pessimistic gpm_optimistic gpm_pessimistic mpg_r2 gpm_r2"
local sharevars_r ""

foreach var of local sharevars {
	bys quarter year OwnerZipCode: gegen ta_`var' = total(area) if !mi(`var')
	gen sa_`var' = area/ta_`var'
	replace `var' = `var'*sa_`var'
	drop sa_`var' ta_`var'
	
	bys quarter year OwnerZipCode: gegen ta_`var' = total(area) if !mi(`var') & (DACCensusTractFlag == DACZIPCodeFlag) & !mi(DACZIPCodeFlag)
	gen sa_`var' = area/ta_`var'
	gen `var'_r = `var'*sa_`var'
	drop sa_`var' ta_`var'
	local sharevars_r = "`sharevars_r'" + " `var'_r"
	

}


gcollapse (sum) `sharevars' `sharevars_r' (max) eligibleAQMD, by(OwnerZipCode year quarter)

merge m:1 OwnerZipCode using `CES_ZIP', keep(match master) nogen

tempfile Before_Pop
save `Before_Pop'


// Population
// ----------------------------
** Import zipcode level population data
import delimited using "${EFMPFleetData}/census/ACS popluation, by zcta 2010-15/ACS_15_5YR_B01003_with_ann.csv", case(preserve) varnames(2) stringcols(2) clear
rename (Id2 EstimateTotal) (OwnerZipCode  population)
keep OwnerZipCode population

** Merge Experian with population data
merge 1:m OwnerZipCode using `Before_Pop', ///
	assert(match master using) keep (match using) nogen

	
// 	Zip-level FPL Weights
// ----------------------------
merge m:1 OwnerZipCode using "${EFMPFleetData}/census/ACS data by tract/aff_download/DistributionData.dta"
keep if _merge==3
drop _merge
drop if PL225_frac==.
gen PL_LT400_frac = PL225_frac + PL300_frac + PL400_frac

// EFMP Incentives
// ----------------------------
ren quarter Quarter
ren year CalendarYear 

*destring tract, replace
compress
** Save tempfile	
tempfile Before_EFMP
save `Before_EFMP'

save "${EFMPFleetData}/Before_EFMP.dta", replace



** Define StartDate local
local StartDate = date("March 1 2010", "MDY")

** Import EFMP data
import excel using "${EFMPFleetData}/EFMP/EFMP_Data/participantdata_q4_2017.xlsx", clear firstrow

** Revert to original EFMP variable names
rename GGRFTotal PlusUpIncentiveSUM
gen BaseIncentiveSUM = EFMSTotal + LocalFundingTotal
rename ReplacementVehicleTech VehicleType
rename TotalVehicleIncentive TotalIncentive
replace VehicleType = "HEV" if VehicleType=="Hybrid"|VehicleType=="HYbrid"
replace VehicleType = "Conventional" if VehicleType=="CONVENTIONAL"|VehicleType=="Minivan"
drop if VehicleType=="ALT Transpo"

generate date = yq(CalendarYear, Quarter)
generate NewUsedIndicator = "N" if ReplacementVehicleMY>=CalendarYear
replace NewUsedIndicator = "U" if NewUsedIndicator == ""
keep if date > qofd(`StartDate')

** Correct zipcodes
replace ZipCode = 93305 if ZipCode==3305
replace CensusTract = subinstr(CensusTract, ".", "", .)
sort CensusTract CalendarYear Quarter VehicleType


drop if TotalIncentive == 0 
replace PlusUpIncentiveSUM = 9500 if PlusUpIncentiveSUM>9500

// Applies to BEVs & PHEVs
replace PlusUpIncentiveSUM=5000 if TotalIncentive==9500
replace BaseIncentiveSUM=4500 if TotalIncentive==9500
replace PlusUpIncentiveSUM=4000 if TotalIncentive==7500
replace BaseIncentiveSUM=3500 if TotalIncentive==7500
replace PlusUpIncentiveSUM=3000 if TotalIncentive==5500
replace BaseIncentiveSUM=2500 if TotalIncentive==5500

// Applies to HEVs & Conventional
replace PlusUpIncentiveSUM=2500 if TotalIncentive==7000
replace BaseIncentiveSUM=4500 if TotalIncentive==7000
replace PlusUpIncentiveSUM=2500 if TotalIncentive==6500
replace BaseIncentiveSUM=4000 if TotalIncentive==6500
replace PlusUpIncentiveSUM=1500 if TotalIncentive==5000
replace BaseIncentiveSUM=3500 if TotalIncentive==5000

// Applies to AQMD=1 & DAC=0
replace BaseIncentiveSUM=4500 if TotalIncentive==4500
replace BaseIncentiveSUM=4000 if TotalIncentive==4000
replace BaseIncentiveSUM=3500 if TotalIncentive==3500


// All non-round subsidies
	
replace BaseIncentiveSUM = 3500 if TotalIncentive>7000&TotalIncentive<7500
replace PlusUpIncentiveSUM = TotalIncentive - 3500 if TotalIncentive>7000&TotalIncentive<7500

replace BaseIncentiveSUM = 4500 if TotalIncentive>7500&TotalIncentive<9500
replace PlusUpIncentiveSUM = TotalIncentive - 4500 if TotalIncentive>7500&TotalIncentive<9500

replace TotalIncentive = BaseIncentiveSUM + PlusUpIncentiveSUM

tab  PlusUpIncentive VehicleType, col
tab NewUsed VehicleType, col

save "${EFMPFleetData}/EFMP_Incentives_precollapse.dta", replace



use "${EFMPFleetData}/EFMP_Incentives_precollapse.dta", clear

sort ZipCode CalendarYear Quarter VehicleType New
replace VehicleType = "ICE" if VehicleType == "Conventional"

** Create incentive totals and counts
foreach i in TotalIncentive BaseIncentiveSUM PlusUpIncentiveSUM {
	replace `i'=. if `i'==0
	bysort ZipCode CalendarYear Quarter: gegen cnt`i'=count(`i')
		
		levelsof VehicleType, local(vehicletypes_local) 
		foreach type of local vehicletypes_local {
			bysort ZipCode CalendarYear Quarter: gegen cnt`i'`type' = count(`i') if VehicleType == "`type'"
			gen `i'`type' = `i' if VehicleType == "`type'"
		}
}

sort ZipCode CalendarYear Quarter New VehicleType

gcollapse (sum) TotalIncentive* BaseIncentiveSUM* PlusUpIncentiveSUM* ///
	(mean) cntTotalIncentive* cntBaseIncentiveSUM* cntPlusUpIncentiveSUM*, ///
	by(ZipCode CalendarYear Quarter)

	
foreach var of varlist cntTotalIncentive* cntBaseIncentiveSUM* cntPlusUpIncentiveSUM* {
	replace `var' = 0 if `var' == .
}
** Rename and string census
ren ZipCode OwnerZipCode

drop if OwnerZipCode ==.
tostring OwnerZipCode, replace
compress

** Merge Experian with EFMP incentives	
merge 1:m OwnerZipCode CalendarYear Quarter ///
	using "${EFMPFleetData}/Before_EFMP.dta", keep(match using) nogen

sort OwnerZipCode CalendarYear Quarter 

drop if CalendarYear > 2017 

** Replace missing EFMP levels with zeros
foreach var of varlist TotalIncentive* BaseIncentiveSUM* PlusUpIncentiveSUM* ///
	cntTotalIncentive* cntBaseIncentiveSUM* cntPlusUpIncentiveSUM* {
	replace `var' = 0 if missing(`var')
}

order CalendarYear-PlusUpIncentiveSUM cnt_total cntTotalIncentive

gen cntDiff_EE = cnt_total - cntBaseIncentiveSUM
gen scalingFactor = cnt_total/cntBaseIncentiveSUM if cntDiff_EE<0
foreach i in TotalIncentive BaseIncentiveSUM PlusUpIncentiveSUM {
	replace `i' = `i'*scalingFactor if cntDiff_EE<0
}
foreach i in cntTotalIncentive cntBaseIncentiveSUM cntPlusUpIncentiveSUM {
	replace `i' = `i'*scalingFactor if cntDiff_EE<0
}


// FPL Weights
** Merge Experian with FPL weights
merge m:1 OwnerZipCode using "${EFMPFleetData}/census/ACS data by tract/aff_download/DistributionData.dta", ///
	keep(match master) nogen


local CES20Threshold 36.6

** Generate triple difference dummies and interactions
gen runquarter = (CalendarYear-2010)*4 + Quarter 
gen post = (runquarter>=23) 
gen dac = (MaxCES>=`CES20Threshold') 
ren eligibleAQMD aqmd

/* Incorrectly classified AQMDs based on census tract AQMD map*/ 
/* These zips are listed in SCAQMD according to: https://www.aqmd.gov/docs/default-source/default-document-library/zip_codes_in_scaqmd.xls?sfvrsn=8*/

foreach i in 90747 92318 92385 93243 {
replace aqmd = 1 if OwnerZipCode == "`i'"
}

gen post_dac = post*dac
gen post_aqmd = post*aqmd
gen dac_aqmd = dac*aqmd
gen tripdiff = dac*aqmd*post
gen aqmd_trend = aqmd*runquarter

label var post_dac "DAC*POST"
label var post_aqmd "AQMD*POST"
label var tripdiff "AQMD*DAC*POST"

** Order columns and rows
order OwnerZipCode CalendarYear Quarter ///
	runquarter post dac aqmd ///
	avg_price* mpg* gpm* modelyr* TotalIncentive* BaseIncentiveSUM* PlusUpIncentiveSUM* ///
	cntTotalIncentive* cntBaseIncentiveSUM* cntPlusUpIncentiveSUM*

	
foreach type in mpg gpm {
	replace `type'_optimistic = `type' if tripdiff == 0
	replace `type'_pessimistic = `type' if tripdiff == 0

}

rename TotalIncentive*			EFMP_tot*
rename BaseIncentiveSUM* 		EFMP_base*
rename PlusUpIncentiveSUM*		EFMP_PU*
rename cntTotalIncentive* 		cntEFMP_tot* 
rename cntBaseIncentiveSUM*		cntEFMP_base*
rename cntPlusUpIncentiveSUM*	cntEFMP_PU*
rename avg_price SellPrice


la var SellPrice "Mean sale price"
la var mpg "Average MPG"
la var gpm "Average GPM"
la var modelyr "Mean model year"
la var cnt_mmy  "Average transaction count for MMY"
la var cnt_total "total transactions within zip code"
order OwnerZipCode runquarter cnt_total cnt_total* cntE* EFMP_* 

ren cntEFMP_base* efmp_base*
ren cntEFMP_PU* efmp_pu*
foreach var of varlist efmp_base efmp_pu {
	gen frac_`var' = `var'/cnt_total
	label var frac_`var' "share EFMP PU in fleet"
} 

foreach var of varlist efmp_base efmp_pu {
	foreach type of local vehicletypes_local {
		gen frac_`var'`type' = `var'`type'/cnt_total
		label var frac_`var'`type' "share EFMP PU for `type' in fleet"
	}
} 
ren efmp_base* cntEFMP_base*
ren efmp_pu* cntEFMP_PU*


gen qEFMPsubs_pu = frac_efmp_pu*cnt_total
tab qEFMPsubs
tab frac_efmp_pu

gen avgsubsidy_efmp_base = EFMP_base/cnt_total
gen avgsubsidy_efmp_pu = EFMP_PU/cnt_total
gen avgsubsidy_total = avgsubsidy_efmp_base + avgsubsidy_efmp_pu
label var avgsubsidy_efmp_pu "Avg. EFMP PU Subsidy over fleet"
label var avgsubsidy_efmp_base "Avg. EFMP Subsidy  over fleet"
label var avgsubsidy_total "Avg. Total EFMP Subsidy over fleet"


foreach type of local vehicletypes_local {

	gen avgsubsidy_efmp_base`type' = EFMP_base`type'/cnt_total
	gen avgsubsidy_efmp_pu`type' = EFMP_PU`type'/cnt_total
	gen avgsubsidy_total`type' = avgsubsidy_efmp_base`type' + avgsubsidy_efmp_pu`type'
	label var avgsubsidy_efmp_pu`type' "Avg. EFMP PU Subsidy for `type'"
	label var avgsubsidy_efmp_base`type' "Avg. EFMP Subsidy  for `type'"
	label var avgsubsidy_total`type' "Avg. total EFMP Subsidy for `type'"
}

order OwnerZipCode-cntEFMP_PU cnt_total-avgsubsidy_totalPHEV


// Save Dataset
// ----------------------------
compress

/*Drop quarters before Q2 2012*/
drop if CalendarYear == 2011 | (CalendarYear == 2012 & Quarter ==1)

destring OwnerZipCode, replace
ren OwnerZipCode zip

foreach type in mpg gpm {
ren `type'_optimistic `type'O
ren `type'_pessimistic `type'P
ren `type'_r `type'R
ren `type'_r2 `type'R2
}
gen lmpg = log(mpg)
gen lmpgO = log(mpg_optimistic)
gen lmpgP = log(mpg_pessimistic)
gen lmpgR = log(mpg_r)
gen lmpgR2 = log(mpg_r2)
save "${EFMPFleetData}/TransactionData.dta", replace



log close

